<?php
/**
 * Created by PhpStorm.
 * User: s.utkin
 * Date: 09.12.2014
 * Time: 14:14
 */

namespace Messenger\Messages;


use Messenger\Messages;

class AjaxItemAction extends \Action {
	protected static $isPublic = true;
	
	public static function pullParams()
	{
		return ['identity'];
	}

	public function privileges()
	{
		return ['#authorized'];
	}

	/**
	 *
	 */
	protected function run()
	{
		$myProfileId = $this->request->_identity;
		$messageId = $this->request->messageId;
		/** @var Messages $message */
		$message = Messages::find($messageId);

		if (!$message) {
			throw new \Exception("Message '$messageId' not found.", 404);
		}

		$this->response->message = $message;
		$this->response->messageIsMine = $message->belongsToProfile($myProfileId);
	}
}